<?php

use app\model\PageSetting;
use think\migration\Migrator;

class AlterPageSettingAddOldImgage extends Migrator
{

    public function up()
    {
        $sql = <<<SQL
            ALTER TABLE `page_setting` ADD COLUMN `old_image` varchar(250) COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '图片';
SQL;
        $this->execute($sql);
//        echo '图片备份开始'.PHP_EOL;
//        PageSetting::query()
//            ->field('id, image, old_image')
//            ->chunk(100, function ($list) {
//                if (empty($list)) {
//                    return false;
//                }
//                /**
//                 * @var PageSetting $pageSetting
//                 */
//                foreach ($list as $pageSetting) {
//                    $pageSetting->old_image = $pageSetting->image;
//                    $pageSetting->save();
//                }
//            });
//        echo '图片备份完成'.PHP_EOL;
    }

    public function down()
    {
        $this->table('page_setting')->removeColumn('old_image');
    }
}
